package cn.z2huo.demo.kafka.apache.configtest.producer;

import cn.z2huo.core.util.IdUtils;
import cn.z2huo.demo.model.dataobject.user.UserDO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * @author z2huo
 */
@Slf4j
public class DataGeneratorUtils {

    /**
     * 随机生成用户数据
     * @param count 生成数量
     * @return  用户列表
     */
    public static List<UserDO> generateUser(int count) {
        ArrayList<UserDO> userDOS = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            UserDO userDO = new UserDO();
            userDO.setUserCode("userCode " + RandomStringUtils.randomAlphabetic(8))
                    .setUserName("userName " + RandomStringUtils.randomAlphabetic(8))
                    .setId(IdUtils.nextId())
                    .setCreateTime(LocalDateTime.now())
                    .setOperateTime(LocalDateTime.now())
                    .setValidDate(LocalDate.now())
                    .setInvalidDate(LocalDate.now().plusYears(1))
                    .setValidFlag("1")
                    .setDeleteFlag("0");
            userDOS.add(userDO);
        }
        log.info("generate user list success, user count is {}", count);
        return userDOS;
    }

}
